/*
* $Id: ConvertFunction.java 265 2011-02-07 23:13:07Z volok-aleksej@yandex.ru $
*
* Copyright 2008-2011 by Volokitin Alexey
* All rights reserved
*
*/
package apiary.common;

import java.util.Calendar;
import java.util.Date;

/**
 * Helper convert functions
 * @author lexus
 */
public class ConvertFunction
{
    /**
     * Convert long date format to string format
     * @param date date format
     * @return string format
     */
    public static String dateToString (long date){
        Calendar c = Calendar.getInstance();
        c.setTime(new Date(date));
        int y = c.get(Calendar.YEAR);
        int m = c.get(Calendar.MONTH) + 1;
        int d = c.get(Calendar.DATE);
        String t = (d < 10 ? "0" : "") + d + "." +
                   (m < 10 ? "0" : "") + m + "." +
                   (y < 10 ? "0" : "") + y;
        return t;
    }

    /**
     * Convert lond time format to string format
     * @param time time format
     * @return string format
     */
    public static String timeToString (long time)
    {
        Calendar c = Calendar.getInstance();
        c.setTime(new Date(time));
        int h = c.get(Calendar.HOUR_OF_DAY);
        int m = c.get(Calendar.MINUTE);
        int s = c.get(Calendar.SECOND);
        String t = (h < 10 ? "0" : "") + h + ":" +
                   (m < 10 ? "0" : "") + m + ":" +
                   (s < 10 ? "0" : "") + s;
        return t;
    }
}
